package com.qiku.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiku.constants.SystemConstants;
import com.qiku.entity.Link;
import com.qiku.entity.ResponseResult;
import com.qiku.mapper.LinkMapper;
import com.qiku.service.LinkService;
import com.qiku.utils.BeanCopyUtils;
import com.qiku.vo.LinkVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link> implements LinkService {

    @Override
    public ResponseResult getAllLink() {
        LambdaQueryWrapper<Link> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Link::getStatus, SystemConstants.Link_STATUS_NORMAL);
        List<Link> links = list(queryWrapper);
        List<LinkVo> linkVos = BeanCopyUtils.copyBeanList(links, LinkVo.class);
//        List<LinkVo> list = new ArrayList<>();
//        LinkVo vo = new LinkVo();
//        for (Link link : links){
//            BeanUtils.copyProperties(link,vo);
//            list.add(vo);
//        }
        return ResponseResult.okResult(linkVos);
    }
}
